package nuc.edu.tlias.Filter;


import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

//@WebFilter(urlPatterns = "/*")// 拦截所有请求


@Slf4j
public class DemoFilter implements Filter {
    // 初始化
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

        log.info("初始化");
    }


    //解释下面代码的作用 拦截请求
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("拦截请求");
        log.info("请求路径：{}",servletRequest.getServletContext().getContextPath());
        // 放行
        filterChain.doFilter(servletRequest,servletResponse);
        log.info("拦截响应");

    }

    @Override
    public void destroy() {
        log.info("销毁方法");
    }
}
